﻿using Blog.Core.Domain;
using Blog.Core.Domain.Dictionary;
using Blog.Core.Domain.Model;
using Blog.Core.Domain.Model.Quartz;
using Blog.Core.Domain.Model.User;
using Blog.Core.Domain.Model.WorkFlow;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Blog.Core.EFcore
{
    public class MySqlContext:DbContext
    {
        //多个数据库应该使用这个构造函数，参数是上下文的集合

        public MySqlContext(DbContextOptions<MySqlContext> options) : base(options)
        {

        }
        //自定义DbContext实体属性名与数据库表对应名称（默认 表名与属性名对应是 User与Users）

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            /// <summary>
            /// 用户信息表
            /// </summary>
            modelBuilder.Entity<UserInfo>().ToTable("UserInfos");
            /// <summary>
            /// 权限信息表
            /// </summary>

            modelBuilder.Entity<Permissions>().ToTable("Permissions");
            /// <summary>
            /// 角色信息表
            /// </summary>

            modelBuilder.Entity<Roles>().ToTable("Roles");
            /// <summary>
            /// 用户角色关系表
            /// </summary>

            modelBuilder.Entity<RoleUsers>().ToTable("RoleUsers");
            /// <summary>
            /// 角色权限关系表
            /// </summary>

            modelBuilder.Entity<RolePermission>().ToTable("RolePermissions");
            /// <summary>
            /// 部门信息表
            /// </summary>

            modelBuilder.Entity<DepartmentInfo>().ToTable("DepartmentInfos");
            /// <summary>
            /// 角色信息表
            /// </summary>

            modelBuilder.Entity<Permissions>().ToTable("Permissions");
            /// <summary>
            /// 部门用户关系表
            /// </summary>

            modelBuilder.Entity<DepartmentUser>().ToTable("DepartmentUsers");
            /// <summary>
            /// 日志信息表
            /// </summary>

            modelBuilder.Entity<Journal>().ToTable("Journals");
            /// <summary>
            /// 表单设计表
            /// </summary>

            modelBuilder.Entity<FromInfo>().ToTable("FromInfos");
            /// <summary>
            /// 定时任务表
            /// </summary>

            modelBuilder.Entity<QuartzOptions>().ToTable("QuartzOptions");

            /// <summary>
            /// 字典类型表
            /// </summary>
            modelBuilder.Entity<DictType>().ToTable("DictTypes");

            /// <summary>
            /// 字典数据表
            /// </summary>
            modelBuilder.Entity<DictData>().ToTable("DictDatas");

            modelBuilder.Entity<Workflow>().ToTable("Workflows");


            modelBuilder.Entity<Workflowauditlog>().ToTable("Workflowauditlogs");


            modelBuilder.Entity<Workflowtable>().ToTable("Workflowtables");


            modelBuilder.Entity<Workflowtableauditlog>().ToTable("Workflowtableauditlogs");

            modelBuilder.Entity<Workflowtablestep>().ToTable("Workflowtablesteps");
            //相关表名称的和类的对应

            base.OnModelCreating(modelBuilder);

        }
        /// <summary>
        /// 用户信息表
        /// </summary>
        public virtual DbSet<UserInfo> UserInfos { get; set; }
        /// <summary>
        /// 角色信息表
        /// </summary>
        public virtual DbSet<Permissions> Permissions { get; set; }
        /// <summary>
        /// 权限信息表
        /// </summary>
        public virtual DbSet<Roles> Roles { get; set; }
        /// <summary>
        /// 用户角色关系表
        /// </summary>
        public virtual DbSet<RoleUsers> RoleUsers { get; set; }
        /// <summary>
        /// 角色权限关系表
        /// </summary>
        public virtual DbSet<RolePermission> RolePermissions { get; set; }
        /// <summary>
        /// 部门信息表
        /// </summary>
        public virtual DbSet<DepartmentInfo> DepartmentInfos { get; set; }
        /// <summary>
        /// 部门用户关系表
        /// </summary>
        public virtual DbSet<DepartmentUser> DepartmentUsers { get; set; }
        /// <summary>
        /// 日志信息表
        /// </summary>
        public virtual DbSet<Journal> Journals { get; set; }
        /// <summary>
        /// 表单设计表
        /// </summary>
        public virtual DbSet<FromInfo> FromInfos { get; set; }
        /// <summary>
        /// 定时任务表
        /// </summary>
        public virtual DbSet<QuartzOptions> QuartzOptions { get; set; }
        /// <summary>
        /// 字典类型表
        /// </summary>
        public virtual DbSet<DictType> DictTypes { get; set; }
        /// <summary>
        /// 字典数据表
        /// </summary>
        public virtual DbSet<DictData> DictDatas { get; set; }

        public virtual DbSet<Workflow> Workflows { get; set; }

        public virtual DbSet<Workflowauditlog> Workflowauditlogs { get; set; }

        public virtual DbSet<Workflowtable> Workflowtables { get; set; }

        public virtual DbSet<Workflowtableauditlog> Workflowtableauditlogs { get; set; }

        public virtual DbSet<Workflowtablestep> Workflowtablesteps { get; set; }
    }
}
